import requests
import os

def upload_file(url, file_path):
    # 检查文件是否存在
    if not os.path.exists(file_path):
        print(f"文件 {file_path} 不存在")
        return

    # 打开文件
    with open(file_path, 'rb') as file:
        # 构建文件字典
        files = {'file': (os.path.basename(file_path), file)}
        
        # 发送POST请求
        response = requests.post(url, files=files)
        
        # 输出响应结果
        print(f"响应状态码: {response.status_code}")
        print(f"响应内容: {response.text}")

if __name__ == "__main__":
    # 上传文件的URL
    url = "http://localhost:9090/file/upload"
    
    # 要上传的文件路径
    file_path = "./utils/utils.go"
    
    # 调用上传函数
    upload_file(url, file_path)